package com.zrrd.gmall.product.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zrrd.gmall.common.result.Result;
import com.zrrd.gmall.model.product.BaseSaleAttr;
import com.zrrd.gmall.model.product.BaseTrademark;
import com.zrrd.gmall.model.product.SpuInfo;
import com.zrrd.gmall.product.service.SpuInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
public class SpuInfoController {
    @Autowired
    private SpuInfoService spuInfoService;
    @GetMapping("/{page}/{limit}")
    public Result<Page<SpuInfo>> baseTrademark(@PathVariable("page") Integer page,
                                               @PathVariable("limit") Integer limit,
                                               Long category3Id) {
        Page<SpuInfo> pageInfo = new Page<>(page, limit);
        QueryWrapper<SpuInfo> wrapper =new QueryWrapper<>();
        wrapper.eq("category3_id",category3Id);
        wrapper.orderByDesc("id");
        spuInfoService.page(pageInfo,wrapper);
        return Result.ok(pageInfo);

    }
    //查询基本属性列表
    @GetMapping("/baseSaleAttrList")
    public Result<List<BaseSaleAttr>> baseSaleAttrList(){
        List<BaseSaleAttr> baseSaleAttrList = spuInfoService.getBaseSaleAttrList();
        return Result.ok(baseSaleAttrList);
    }
    @PostMapping("/saveSpuInfo")
    public Result<String> saveSpuInfo(@RequestBody SpuInfo spuInfo){
        spuInfoService.saveSupInfo(spuInfo);
        return Result.ok("添加成功");
    }
}
